package com.mgq.juc.c1;

import lombok.extern.slf4j.Slf4j;

/**
 * @author MaGuangQi
 * 测试线程的6种状态
 * @date 2021-12-14 09:41
 **/
@Slf4j
public class TestThreadState {
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            log.debug("t1运行");
        },"t1"); //new
        Thread t2=new Thread(()->{
            synchronized (TestThreadState.class) {
                while (true) {
                    //RUNNABLE
                }
            }

        },"t2");
        t2.start();
        Thread t3=new Thread(()->{
            try {
                Thread.sleep(100000); //time_waiting
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t3");
        t3.start();
        Thread t4=new Thread(()->{
            try {
                t2.join();//wait
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t4");
        t4.start();
        Thread t5=new Thread(()->{
            synchronized (TestThreadState.class) {
                log.debug("线程t5运行"); //BLOCKED
            }
        },"t5");
        t5.start();
        Thread t6=new Thread(()->{
        },"t6");
        t6.start();
        Thread.sleep(1000);
        log.debug("t1状态,{}",t1.getState());
        log.debug("t2状态,{}",t2.getState());
        log.debug("t3状态,{}",t3.getState());
        log.debug("t4状态,{}",t4.getState());
        log.debug("t5状态,{}",t5.getState());
        log.debug("t6状态,{}",t6.getState());
    }
}
